﻿package com.danielsheldon.effects.particles 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author Daniel Sheldon
	 */
	public class ParticleEngine extends Sprite
	{
		private static var _instance:ParticleEngine;
		
		static public function get instance():ParticleEngine { 
			if (_instance == null)
			{
				_instance = new ParticleEngine(new SingletonEnforcer());
			}
			return _instance; 
		}
		
		private static var emitters:Vector.<Emitter> = new Vector.<Emitter>();
		
		public function ParticleEngine(enforcer:SingletonEnforcer)
		{
			//addEventListener(Event.ENTER_FRAME, frameUpdate);
		}
		
		public static function newEmitter(target:DisplayObjectContainer, particle:Class):Emitter 
		{
			var testParticle:* = new particle()
			if (testParticle is IParticle)
			{}
			else 
			{
				throw new Error(enums.ERROR_NEEDS_IPARTICLE);
			}
			
			var newEmitter = new Emitter(particle);
			emitters.push(newEmitter);
			target.addChild(newEmitter);
			
			return newEmitter;
		}
		
		public static function pauseAll():void
		{			
			for each (var emitter:Emitter in emitters)
			{
				emitter.pause();
			}
		}
		
		public static function resumeAll():void
		{			
			for each (var emitter:Emitter in emitters)
			{
				emitter.resume();
			}
		}
	}
}

internal class SingletonEnforcer{ };
